import time
import pytest
import allure
import TestCase

from Base.InitDriver import init_driver
from Page.CommonPage import CommonPage
from Utils.XiaoMaUtils import XiaoMaUtils

from Utils.PerfDogUtils import PerfDogUtils


@allure.feature('TestCase_31: 桌面纯待机1H消耗的流量小于等于100KB	')
@allure.issue(
    'https://www.tapd.cn/56767367/sparrow/tcase/view/1156767367001062245?url_cache_key=ab49d6eabe9823050826460ca132aea4')
class TestCaseSpecial31:
    def setup_class(self):
        self.driver = init_driver()
        # 实例化页面
        # 桌面
        self.launcher_index_page = CommonPage(self.driver).get_launcher_index_page()
        self.launcher_app_list_page = CommonPage(self.driver).get_launcher_app_list_page()

        # 实例化PerfDogUtils的工具类
        # 开始监控
        self.perfDogUtils = PerfDogUtils()
        # 输入需监控的应用名, 如"xting", "music"
        self.perfDogUtils.start_test("launcher")

    def teardown_class(self):
        self.perfDogUtils.stop_test()
        XiaoMaUtils.close_app('launcher')
        # XiaoMaUtils.clear_data('app')
        self.driver.quit()

    @allure.story('step1:进入桌面,杀掉桌面')
    @pytest.mark.run(order=311)
    def test_special_31_1_is_display(self):
        try:
            text1 = self.launcher_index_page.is_display_app_list_btn()
            if text1 == True:
                print("桌面进入成功")
            else:
                print("桌面启动失败")
        except Exception as e:
            raise e
        finally:
            allure.attach(self.driver.get_screenshot_as_png(), XiaoMaUtils.get_current_time(),
                          allure.attachment_type.PNG)

    @allure.story('step2:等待一个小时,查看流量消耗')
    @pytest.mark.run(order=312)
    def test_special_31_2_wait(self):
        try:
            print("当前正在测试流量,请不要结束进程和更改页面")
            time.sleep(15)
            # time.sleep(3600)
        except Exception as e:
            raise e
        finally:
            allure.attach(self.driver.get_screenshot_as_png(), XiaoMaUtils.get_current_time(),
                          allure.attachment_type.PNG)


if __name__ == 'main__':
    # pass
    pytest.main("-s testcase_special_launcher_31.py")
